package com.xiaoyuan.service.impl;

import com.xiaoyuan.dao.Student;
import com.xiaoyuan.minicore.core.ConfigHelper;
import com.xiaoyuan.minicore.dao.DBHelper;
import com.xiaoyuan.minicore.ioc.annotation.Bean;
import com.xiaoyuan.minicore.ioc.annotation.Inject;
import com.xiaoyuan.minicore.tx.annotation.Transaction;
import com.xiaoyuan.service.StudentService;
import com.xiaoyuan.service.StudentService2;

/**
 * @Auther: xiaoyuan
 * @Date: 2020/4/28
 * @Description:
 */
@Bean
public class StudentServiceImpl implements StudentService{

    @Inject
    private StudentService2 studentService2;

    @Override
    public Student getStudentById(Integer id) {
        String sql = ConfigHelper.getString("select.student.id");
        return DBHelper.queryBean(Student.class, sql, id);
    }

    @Override
    @Transaction
    public int insertStudent(String name, String xxHa) throws IllegalAccessException {
        String sql = ConfigHelper.getString("insert.student");

        int result = DBHelper.update(sql,name,xxHa);
        int result2 = studentService2.insertStudent(name+"2", xxHa+"2");
        if(false){
            throw  new IllegalAccessException("StudentService1 error");
        }
        return result;
    }
}
